
package me.zhengjie.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.domain.AppWorkGps;
import me.zhengjie.service.AppWorkGpsService;
import me.zhengjie.service.dto.AppWorkGpsQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @website https://el-admin.vip
* @author IQW
* @date 2022-07-03
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "GPS上传管理")
@RequestMapping("/api/appWorkGps")
public class AppWorkGpsController {

    private final AppWorkGpsService appWorkGpsService;

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('appWorkGps:list')")
    public void exportAppWorkGps(HttpServletResponse response, AppWorkGpsQueryCriteria criteria) throws IOException {
        appWorkGpsService.download(appWorkGpsService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询GPS上传")
    @ApiOperation("查询GPS上传")
    @PreAuthorize("@el.check('appWorkGps:list')")
    public ResponseEntity<Object> queryAppWorkGps(AppWorkGpsQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(appWorkGpsService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
     * 查询谋个任务的所有轨迹
     * @param criteria
     * @return
     */
    @PostMapping(value = "/one")
    public ResponseEntity<Object> queryAppWorkGpsOne(AppWorkGpsQueryCriteria criteria,@RequestBody AppWorkGps resources){
        if(null != resources.getWorkId()){
            criteria.setWorkId(resources.getWorkId());
        }
        return new ResponseEntity<>(appWorkGpsService.queryAll(criteria),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增GPS上传")
    @ApiOperation("新增GPS上传")
    @PreAuthorize("@el.check('appWorkGps:add')")
    public ResponseEntity<Object> createAppWorkGps(@Validated @RequestBody AppWorkGps resources){
        return new ResponseEntity<>(appWorkGpsService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改GPS上传")
    @ApiOperation("修改GPS上传")
    @PreAuthorize("@el.check('appWorkGps:edit')")
    public ResponseEntity<Object> updateAppWorkGps(@Validated @RequestBody AppWorkGps resources){
        appWorkGpsService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除GPS上传")
    @ApiOperation("删除GPS上传")
    @PreAuthorize("@el.check('appWorkGps:del')")
    public ResponseEntity<Object> deleteAppWorkGps(@RequestBody Integer[] ids) {
        appWorkGpsService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}